//
//  BaseTabbarController.m
//  JTProject
//
//  Created by Yuki on 2021/3/9.
//

#import "BaseTabbarController.h"
#import "BaseNavigationController.h"///导航栏
#import "ELHomeController.h" ///首页
#import "ELMyController.h"///我的
@interface BaseTabbarController ()<RDVTabBarControllerDelegate>

@end

@implementation BaseTabbarController
- (void)viewDidLoad {
    [super viewDidLoad];
    
    ///设置tabbar的背景色
    self.tabBar.backgroundView.backgroundColor = ColorHex(0xFFbb00, 1);
    ///创建界面
    [self _setupView];
    
    self.delegate = self;

}


///创建界面
- (void)_setupView{
    ELHomeController *firstVc = [[ELHomeController alloc]init];
    BaseNavigationController *firstNav = [[BaseNavigationController alloc]initWithRootViewController:firstVc];
    
    ELMyController *mineVc = [[ELMyController alloc]init];
    BaseNavigationController *mineNav = [[BaseNavigationController alloc]initWithRootViewController:mineVc];
    
    self.viewControllers = @[firstNav, mineNav];
    
    NSArray *itemImgAry = @[@"tabbar_first_",@"tabbar_mine_"];
    NSArray *tileAry = @[@"首页",@"我的"];
    
    ///设置item的图片和文字
    for (int index = 0; index <itemImgAry.count; index ++) {
        RDVTabBarItem *item = [[self tabBar] items][index];
        
        //图片
        UIImage *selectedimage = [UIImage imageNamed:[NSString stringWithFormat:@"%@selected",[itemImgAry objectAtIndex:index]]];
        UIImage *unselectedimage = [UIImage imageNamed:[NSString stringWithFormat:@"%@normal",[itemImgAry objectAtIndex:index]]];
        
        //标题
        [item setTitle:tileAry[index]];
        item.selectedTitleAttributes = @{
            NSFontAttributeName: [UIFont boldSystemFontOfSize:17],
            NSForegroundColorAttributeName:ColorHex(0xd81e06, 1),
        };
        item.unselectedTitleAttributes = @{
            NSFontAttributeName: [UIFont boldSystemFontOfSize:17],
            NSForegroundColorAttributeName:ColorHex(0xe6e6e6, 1),
        };
        
        //标题与图片间距
        item.titlePositionAdjustment = UIOffsetMake(0, 5);
        
        //        item.badgeTextFo
        item.badgePositionAdjustment = UIOffsetMake(0, 10);
        [item setFinishedSelectedImage:selectedimage withFinishedUnselectedImage:unselectedimage];
    }
    
}

- (void)tabBarController:(RDVTabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController{
    ///加载动画
    [tabBarController.tabBar.items enumerateObjectsUsingBlock:^(__kindof UIBarButtonItem * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        RDVTabBarItem *item= (RDVTabBarItem *)obj;
        if ([item.title isEqualToString:@"首页"]) {

        }
    }];
}
- (void)tabBarController:(RDVTabBarController *)tabBarController didSelectItemAtIndex:(NSInteger)index{
    NSLog(@"选中了第%zd个",index);
}

@end
